package com.hust.bridgecheck.controller.UserManagement;

import com.hust.bridgecheck.entity.UserGroup;
import com.hust.bridgecheck.service.UserManagement.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
@RequestMapping("group")
public class GroupController {


    @Autowired
    private GroupService groupService;

    @PostMapping("/add")
    @ResponseBody
    private void addGroup(UserGroup userGroup){
        groupService.addGroup(userGroup);
    }

    @DeleteMapping("/delete/{id}")
    private String deleteGroup(@PathVariable("id") Integer GroupID){
        groupService.deleteGroup(GroupID);
        return "redirect:/group/manager";
    }

    @GetMapping("/all")
    @ResponseBody
    private List<UserGroup> getAllGroup(){

        return groupService.getAllGroup();
    }

    @GetMapping("/getbyid")
    @ResponseBody
    private UserGroup getGroupByID(Integer GroupID){

        return groupService.getGroupByID(GroupID);
    }

    @PutMapping("/updategroup")
    @ResponseBody
    private void updateGroup(UserGroup userGroup){

        groupService.updateGroup(userGroup);
    }
}
